package com.videoadmin.dao.impl;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;

import com.videoadmin.dao.IVipTypeDAO;
import com.videoadmin.pojo.VipType;
import com.videoadmin.utils.HibernateUtil;

public class VipTypeDAOImpl implements IVipTypeDAO {
	
	/* (non-Javadoc)
	 * @see com.video.dao.IVip_TypeDao#saveOrUpdate(com.domain.Vip_Type)
	 */
	public void saveOrUpdate(VipType type){
		Session s = null;
		Transaction ts = null;
		try {
			s = HibernateUtil.getSession();
			ts = s.beginTransaction();
			s.saveOrUpdate(type);
			ts.commit();
		} catch (HibernateException e) {
			if (ts != null)
				ts.rollback();
			throw e;
		} finally {
			if (s != null)
				s.close();
		}
	}
	/* (non-Javadoc)
	 * @see com.video.dao.IVip_TypeDao#delete(com.domain.Vip_Type)
	 */
	public void delete(VipType type){
		Session s = null;
		Transaction ts = null;
		try {
			s = HibernateUtil.getSession();
			ts = s.beginTransaction();
			s.delete(type);
			ts.commit();
		} catch (HibernateException e) {
			if (ts != null)
				ts.rollback();
			throw e;
		} finally {
			if (s != null)
				s.close();
		}
	}
	/* (non-Javadoc)
	 * @see com.video.dao.IVip_TypeDao#findById(int)
	 */
	public VipType findById(int id){
		Session s = null;
		try {
			s = HibernateUtil.getSession();
			VipType type = (VipType) s.get(VipType.class, id);
			return type;
		} finally {
			if (s != null)
				s.close();
		}
	}

}
